package org.abstractmeta.commandify.core.command.util;

import org.abstractmeta.commandify.Commandify;

import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: adrianwit
 * Date: 7/5/13
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */
public class CommandifyUtil {

    public static void dissociateAccessor(Object instance) {
        if (instance instanceof Commandify) {
            Commandify.class.cast(instance).getCommands().dissociateOwnerSelfCommandAccessor();
        }
    }

    public static void dissociateAccessor(Collection<Object> objectCollection) {
        for (Object item : objectCollection) {
            dissociateAccessor(item);
        }
    }


    public static void associateAccessor(Object accessible, Commandify owner, Object source) {
        if (!(accessible instanceof Commandify)) {
            return;
        }
        Commandify commandify = Commandify.class.cast(accessible);
        commandify.getCommands().associateOwnerSelfCommandAccessor(owner, source);
    }

}
